import App from './App'

// #ifndef VUE3
import Vue from 'vue'

import Cfg from '@/common/config.js'
import Cry from '@/common/crypto.js'
import Upd from '@/common/upgrade.js'
import Msg from '@/common/message.js'
import Net from '@/common/request.js'
import Nav from '@/common/navigation.js'
import Tp from '@/common/image-tools.js'

Vue.config.productionTip = false

//设置底部语言 
const setFbar = (index,title) =>{
	uni.setTabBarItem({
	    index: index,
	    text: title
	});
}
//设置标题
const setTitle = (title)=>{
	uni.setNavigationBarTitle({
	    title: title
	});
}
//自动标题
const autoTitle = (lang)=>{
	if(lang && lang.hasOwnProperty('title')){
		setTitle(lang.title);
	}
}
//自动底部导航切换语言
const autoFbar = (lang)=>{
	let fb = lang.r.fbar;
	let i = 0;
	fb.forEach((item)=>{
		uni.setTabBarItem({
		    index: i,
		    text: item
		});
		i++;
	});	
}

//取得属性
const attr = (name,e)=>{
	return e.currentTarget.dataset[name];	
}

//页面跳转
const goPage = (obj,type) =>{	
	if(null == obj)return false;
	let url = attr('url',obj);
	if(type == undefined) type = 0;
	if(url){
		if(type == 0)uni.navigateTo({url:url})
		if(type == 1)uni.redirectTo({url:url})
		if(type == 2)uni.switchTab({url:url})
	}
}

Vue.prototype.api = {
	setFbar,setTitle,autoTitle,autoFbar,attr,goPage
}

Vue.prototype.Cfg = Cfg;//配置相关
Vue.prototype.Cry = Cry;//加密相关
Vue.prototype.Upd = Upd;//更新相关
Vue.prototype.Msg = Msg;//提示相关
Vue.prototype.Net = Net;//网络相关
Vue.prototype.Nav = Nav;//页面切换相关
Vue.prototype.Tp = Tp;	//图片工具

App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif